home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-23 | 12.6 KB | 274 lines | [TEXT/ttxt] |
- 6 Working with Files
- This section describes the MacDOS commands which let you
- work with files.
-
- Many MacDOS commands operate on files. To tell MacDOS where
- to look for them, you specify the folder which contains
- them. If you do not specify any folder, MacDOS looks for
- the files in the current folder.
-
- Identifying a File
- Like with folders, you identify a file through its name and
- its location. Therefore, to identify a file you must
- provide:
- • The ID of the volume which contains the file.
- • The name of all folders, one inside the other, which
- you need to open in order to "reach" from the root the
- file you are looking for.
- • The name of the file.
-
- To fully identify a file in MacDOS you need to type
- something like this:
- 1:\fold1\aDeeperFold\still deeper\myFile
- and all the considerations made in the previous section
- concerning folders apply to files.
-
- File names are strings of up to 31 characters in length.
- They are not allowed to contain colons, and you should also
- avoid other special characters, as they can create problems
- and confusion. For example, if you include a slash in a
- filename and then forget to double quote the name when you
- use it in a command, MacDOS will interpret the part
- beginning with the slash as a switch. Moreover, most MacDOS
- commands reject as bad switches names beginning with a
- slash, whether you double quote them or not. For similar
- reasons, you should also avoid backslashes. Also note that
- if you include a comma in a filename, you will have
- problems in copying it, because the command COPY accepts
- comma-separated filenames. In general, try to avoid
- characters which are used as separators.
-
- Creating New Files
- There are three ways of creating a new file with MacDOS:
- • Create a file with the command OPEN and then write
- into it lines of text with the command WRITE (please
- refer to one of the following sections for the details).
- • Use the command LOG to record all the commands
- executed by MacDOS (please refer to the "Getting Info"
- section of this User's Guide).
- • Redirect the output of a MacDOS command to a disk
- file (please refer to "The Environment" section of this
- User's Guide).
-
- By default, the files created are of type 'TEXT' and
- creator 'ttxt' (ie. TeachText), but you can change the
- creator by updating the system variable CREATOR.
-
- Removing Files
- You can remove files with the commands DEL and ERASE. The
- two commands have different names but are identical for
- what concerns functionality. Therefore, what is said about
- DEL always applies 100% to ERASE.
-
- DEL accepts a single parameter which specifies the file you
- want to delete or the folder you want to empty of files. If
- you include wildcard characters in the parameter, DEL
- deletes all the files whose names match the parameter. You
- also have the possibility of selecting files on the basis
- of their creator, type, or both.
-
- To delete all the files in a particular folder, you can
- pass to DEL a "catch all" filename or simply the name of
- the folder:
- del D:\theFolder\*
- del D:\theFolder
- In either case, MacDOS prompts you for confirmation.
-
- Note that DEL permanently removes the files from the system
- rather than simply moving them to the Trash. To limit the
- danger of such a drastic behaviour, MacDOS prompts you for
- confirmation before deleting each individual file.
- Nevertheless, you can switch this safeguard off by
- executing the command CONFIRM OFF . To re-enable the
- prompting for a single DEL command, add the switch /P. To
- re-enable it permanently, execute the command CONFIRM ON .
-
- Listing Files
- You can list files with two commands: MORE and TYPE.
-
- MORE displays the content of the data fork of files of type
- 'TEXT' one page at a time. At the end of each page, MORE
- waits for you to type any character before continuing. You
- can also interrupt the listing by pressing cmd-dot (or cntl-
- C). MORE is a special command, in that it expects that you
- specify a file as input redirection rather than as a
- parameter. So, if you want to list the file
- 2:\aFold\theFile, you must type:
- more <2:\aFold\theFile
- rather than simply:
- more 2:\aFold\theFile
-
- TYPE, when used in its basic form, also lists the data fork
- of files of type 'TEXT' on the monitor screen. The
- differences are that TYPE expects a file specification as a
- parameter and only stops when it reaches the End Of File
- (EOF). You can pause and resume long listings with cntl-S
- and cntl-Q respectively.
-
- To list the data or resource fork of any file (not only
- text files), use TYPE with the switches /H and /R
- respectively. TYPE then lists the requested fork in HEX, as
- well as in ASCII, 16 bytes per line.
-
- Copying Files
- To copy files, you can use the commands COPY and XCOPY.
- This section only describes COPY. Please refer to the
- section "Working with Folders" for a description of XCOPY.
-
- In its simplest form, COPY makes a duplicate of a file
- which already exists and places it in the current folder:
- copy aFileSpec . The difference with the "Duplicate" menu
- item provided by the Finder is that COPY's duplicate has
- the same name as the original file. Therefore, if you COPY
- a file which already is in the current folder, your command
- does not have any visible effect and you do not get any
- duplicate at all.
-
- If you pass to COPY a second file specification, you can:
- • specify a different name for the duplicate;
- • place the duplicate anywhere in the system rather
- than in the current folder.
- The two file specifications are usually called "source" and
- "destination". With this format, you can reproduce the
- Finder's Duplicate function as follows:
- copy fileName "fileName copy"
- A duplicate of the file fileName in the current folder (ie.
- the front window) is created and named fileName copy. Note
- that the double quotes are only necessary because the new
- name contains a space.
-
- If you use the destination to specify a folder rather than
- a file, the duplicate file is created with the same name as
- the original. In other words, the two following commands
- are equivalent:
- copy fileName destFolder\fileName
- copy fileName destFolder
-
- Still using the second parameter to specify a folder, you
- have three ways of COPYing several files at a time:
-
- • By replacing the single source with a series of file
- specifications separated by commata, you COPY all the
- individual source files to the destination folder:
- copy file1,aFold\file2,2:file3 destFolder
-
- • By wildcarding the source, you COPY all the files
- with matching filenames to the destination folder:
- copy sourceFolder\p*a??? destFolder
-
- • By using the first parameter to specify a folder
- rather than a file, you COPY all the files in the source
- folder to the destination folder:
- copy sourceFolder destFolder
-
- If you specify more than one file as a source parameter but
- use the second parameter to specify a single file, COPY
- merges all the sources to produce the destination. This can
- be useful to append to each other several data or text
- files.
-
- COPY supports several options:
- • Append the source to an existing destination.
- • Only copy files of a given Creator or Type.
- • Only copy the Data or Resource fork of files.
- • Display a Prompt before overwriting destination files.
- • Only copy files which either do not exist in the
- destination folder or do exist but have an older Update
- date and time.
- • Verify that the copies are correct.
-
- Renaming Files
- To rename files, you can use the commands REN and RENAME.
- Apart from their name, the two commands are identical.
-
- In its simplest format, REN works as follows:
- ren fileSpec newName
- The first parameter specifies the file to be renamed and
- the second parameter tells MacDOS what the new name should
- be.
-
- If the first parameter ends with a wildcarded filename, all
- the files with matching names are renamed. In that case,
- the second parameter is used to replace in each name the
- part which precedes the first wildcard character. For
- example:
- ren abc* xyz
- renames abc to xyz, abcf to xyzf, "abc whatever" to
- "xyz whatever", etc. In this form, REN can also be used to
- insert a string before all filenames:
- ren * prependThis
-
- MacDOS also accepts wildcards in the second parameter. In
- that case, MacDOS matches the groups of wildcards and
- replaces the corresponding parts.
-
- If the first parameter specifies a folder rather than a
- file, MacDOS renames all the files in the folder.
- Therefore, the two following commands have identical
- results:
- ren aFold\* x*z
- ren aFold x*z
- In both cases, MacDOS prepends an 'x' and appends a 'z' to
- the name of each file in the folder aFold.
-
- Through a series of options, REN also lets you select files
- on the basis of their creator and type. You can also
- specify whether the name selection should be case sensitive
- or not.
-
- Changing File Attributes
- You can use the command REN and (RENAME, which is
- identical) to change more than just the names of files. In
- particular, you can:
- • set new creators;
- • set new file-types;
- • set the date and time of the last update to the
- current date and time;
- • hide a visible file and viceversa.
-
- This functionality is controlled through switches. For
- example, "ren zz /h" hides the file named zz, and
- "ren/c!????" changes the creator of all files in the
- current folder to '????' (be careful!).
-
- Printing Text Files
- You can print files of type 'TEXT' with the command PRINT.
- The format of PRINT is: print fileSpec .
-
- The file specification can be wildcarded or can be replaced
- with a folder specification, in which case all text files
- in the folder are printed. Without parameter, PRINT prints
- what is displayed in the console window.
-
- Before PRINTing, you can specify the page format with the
- standard "Page Setup ..." item of the File menu.
-
- Instead of displaying the standard Print dialog every time
- you print, MacDOS prints with a default selection, so that
- you can PRINT several files without having to click for
- each one of them. With the /D switch you can direct MacDOS
- to display the standard "Print..." dialog before printing
- the first file.
-
- Direct File I/O
- MacDOS lets you OPEN, READ or WRITE, and CLOSE files of
- type 'TEXT'.
-
- You can OPEN a file for reading, writing, or appending. In
- each case, one line of text at a time is transferred in
- each I/O operation, either from disk to memory or from
- memory to disk. When READing, you can store the line into a
- global variable for later processing, or display it for
- immediate view.
-
- After you have READ from a file the last line, MacDOS
- automatically closes it.
-
- By default, MacDOS creates new files with creator 'ttxt'
- (ie. TeachText), but you can change it by setting the
- system variable CREATOR to your preferred creator.
-
- Type OPEN without parameters to display the list of files
- which are currently open.
-
-